﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;

/// <summary>
/// Summary description for NguoiDung
/// </summary>
public class NguoiDung:DBHelper
{
	public NguoiDung()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    
    public bool CheckUser(string username, string password)
    {
        var db = new LanAnhDataContext(ConnectionString);
        //var user = from u in db.nguoidungs
        //           where u.taikhoan == username && u.matkhau == password
        //           select u;
        var user = db.sp_DangNhap(username, password);
        if (user.Count() > 0)
        {
            return true;
        }
        return false;
        
    }

    public string GetName(string username)
    {
        using (var db = new LanAnhDataContext(ConnectionString))
        {
            var nguoidung = db.nguoidungs.Single(u => u.taikhoan == username);
            string kq = nguoidung.hoten;
            return kq;
        }
    }

    public static List<nguoidung> UserList()
    {
        using (var db = new LanAnhDataContext(ConnectionString))
        {
            var user = from u in db.nguoidungs
                       select u;
            return user.ToList();
        }
    }
    public static IEnumerable GetUserName()
    {
        using (var db = new LanAnhDataContext(ConnectionString))
        {
            var usernames = db.nguoidungs.OrderBy(l => l.taikhoan);
            return usernames.ToList();
        }
    }

}